<template>
	<view class="box">
		<view class="list-cell-user" v-for="(item, index) in contentList" @click="toDetail(item.id)">
			<view class="user">
				<image class="avatar" :src="item.avatar" mode="aspectFill"
					style="height: 70rpx;width: 70rpx;border-radius: 10rpx;margin:0 35rpx 0 0;">
				</image>
				<view class="name">
					{{item.username}}
				</view>
				<view class="time">
					{{item.time}}
				</view>
			</view>

			<view class="title">
				{{item.title}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		listMyPost
	} from "@/api/post";

	export default {
		data() {
			return {
				// 我的帖子
				contentList: [{
					id: 0,
					avatar: '',
					username: '',
					title: '',
					time: ''
				}],
			};
		},
		onLoad() {
			this.getPostList();
		},
		methods: {
			// 获取自己的帖子
			getPostList() {
				this.$modal.loading("正在加载数据");
				this.loading = true
				listMyPost().then(response => {
					console.log(response.data);
					this.contentList = response.data

					// 加载条消失
					this.loading = false;
					this.$modal.closeLoading()
				})
			},

			// 跳转到帖子详情界面
			toDetail(id) {
				wx.navigateTo({
					url: "/pages/community/detail/detail?postId=" + id
				})
			},
		}
	}
</script>

<style lang="scss">
	.box {

		// 论坛主体
		.list-cell-user {
			display: flex;
			align-items: center;
			box-sizing: border-box;
			width: 100%;
			padding: 10rpx 24rpx;
			overflow: hidden;
			color: #323233;
			font-size: rpx;
			line-height: 24rpx;
			background-color: #fff;
			flex-direction: column;
			margin: 15rpx 0;

			.user {
				display: flex;
				align-items: center;
				width: 100%;

				.avatar {
					height: 70rpx;
					width: 70rpx;
					border-radius: 10rpx;
					margin-right: 35rpx;
				}

				.name {
					flex: 1;
					margin-left: 10rpx;
					font-size: 40rpx;
					font-weight: 500;
				}

				.time {
					text-align: right;
					margin-top: 5rpx;
					color: gray;
				}
			}

			.title {
				width: 100%;
				flex: 1;
				margin-top: 10rpx;
				text-align: left;
				font-size: 35rpx;
				margin: 20rpx 0;
				padding: 15rpx 0 0 25rpx;
			}
		}
	}
</style>